package com.ssm.studen.service.impl;

import com.ssm.studen.dao.ExampaperDao;
import com.ssm.studen.model.Exampaper;
import com.ssm.studen.service.ExampaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 试卷表：
 *      实现业务及流程接口当中的内容
 */
@Service
public class ExampaperServiceImpl implements ExampaperService {

    @Autowired
    private ExampaperDao exampaperDao;


    /**
     * 试卷表的添加
     * @param exampaper
     * @return
     */
    @Override
    public int addExampaper(Exampaper exampaper) {
        int add = 0;
         //判断试卷表中是否存在试卷
        if(exampaper.getEpname()!=null||exampaper.getEpclass()!=null||exampaper.getEptid()!=null){
            exampaperDao.insertExampaper(exampaper);
        }else{
            add = -1;
        }
        return add;
    }


    /**
     * 试卷表的修改更新
     * @param exampaper
     * @return
     */
    @Override
    public int updateExampaper(Exampaper exampaper) {
        int isUpdate = 0;
        try {
            isUpdate = exampaperDao.updateExampaper(exampaper);
        }catch (Exception e){
            isUpdate = -1;
            //打印更新时报错的情况
            System.out.println("更新试卷表信息时执行SQL报错的原因是：" + e.getMessage());
        }
        return isUpdate;
    }


    /**
     * 试卷表的查询
     * @param epnum
     * @return
     */
    @Override
    public List<Exampaper> selectExampaper(int epnum) {
        List<Exampaper> exampapers = exampaperDao.selectExampaper(epnum);
        return exampapers;
    }
}




















